#include "projectile.h"

Projectile::Projectile(Game* game) : Model(game) {
    this->life = 2;
    this->light = NULL;
    this->SetScale(0.01f);
    this->SetModelFilename("sphere.txt");
    this->SetTextureFilename("red.bmp");
}

Projectile::~Projectile(void) {
    if (this->light != NULL) {
        this->GetGame()->GetLightManager()->Remove(this->light);
        delete this->light;
    }
}

Vector4 Projectile::GetDirection() const {
    return this->direction;
}

void Projectile::SetDirection(Vector4 val) {
    this->direction = val;
}

float Projectile::GetLife() const {
    return this->life;
}

Light* Projectile::GetLight() const {
    return this->light;
}

void Projectile::Draw(float timeDelta) {
    Vector4 amb = this->GetGame()->GetLightManager()->GetAmbientLight();
    this->GetGame()->GetLightManager()->SetAmbientLight(Vector4(1, 0, 0, 0));
    Model::Draw(timeDelta);
    this->GetGame()->GetLightManager()->SetAmbientLight(amb);
}

void Projectile::Initialize() {
    this->light = new Light();
    this->light->attenuation0 = 0.0f;
    this->light->attenuation1 = 0.5f;
    this->light->attenuation2 = 0.0f;
    this->light->color = Vector4(1.0f, 0.0f, 0.0f, 1.0f);
    this->light->position = this->position;
    this->light->type = LIGHTTYPE_POINT;
    this->GetGame()->GetLightManager()->Add(this->light);
}

void Projectile::Update(float timeDelta) {
    this->SetPosition(this->GetPosition() + this->direction * 1000 * timeDelta);
    this->light->position = this->position;
    this->life -= timeDelta;
}

